package com.tc.gateway.device.remote;

import java.util.ArrayList;
import java.util.Collection;

import com.byq.mm.abstractx.cluster.server.executor.Executor;
import com.byq.mm.abstractx.device.Cluster;
import com.byq.mm.application.cluster.provider.ObdProvider;
import com.byq.mm.application.cluster.provider.OnoffProvider;
import com.byq.mm.application.cluster.provider.TunnelProvider;
import com.byq.mm.application.cluster.server.ObdServer;
import com.byq.mm.application.cluster.server.OnoffServer;
import com.byq.mm.application.cluster.server.SimpleSensorServer;
import com.byq.mm.application.cluster.server.TunnelServer;
import com.byq.mm.application.cluster.server.executor.ObdExecutor;
import com.byq.mm.application.cluster.server.executor.OnoffExecutor;
import com.byq.mm.foundation.cluster.datatype.ByteArrayValue;
import com.byq.mm.foundation.cluster.datatype.DoubleRangeValue;
import com.byq.mm.foundation.cluster.datatype.DoubleValue;
import com.byq.mm.foundation.cluster.datatype.StringValue;
import com.byq.mm.foundation.cluster.server.BasicClusterServer;
import com.tc.gateway.device.listener.SimpleSensorListener;
import com.tc.gateway.device.type.SimpleSensorDevice;

public class SimpleSensorController extends RemoteController<SimpleSensorDevice> implements SimpleSensorListener{
	
	public SimpleSensorController(SimpleSensorDevice device) {
		super(device);
	}

	SimpleSensorServer server;
	public Executor getExecutor(BasicClusterServer s) {
		server = (SimpleSensorServer)s; 
		server.onValueChange(new DoubleValue(device.getValue()));
		server.setRange(new DoubleRangeValue(device.getMin(), device.getMax()));
		server.setUnit(new StringValue(device.getUnit()));
		
		return new Executor(){
		};
	}


	public void onLevel(double level) {
		server.onValueChange(new DoubleValue(level));
		
	}

	public void range(double min, double max) {
		server.setRange(new DoubleRangeValue(min,max));
		
	}

	@Override
	protected Collection<Cluster> getSupportedClusters() {
		Collection<Cluster> rst = new ArrayList<Cluster>();
		Cluster c = new Cluster();
		c.setId(com.byq.mm.cluster.provider.SimpleSensorProvider.Define.CLUSTER_NAME);
		rst.add(c);
		return rst;
	}

	
}
